package com.it.od.od2024.od20240203;

import java.util.Scanner;

/**
 * @author: liminghui
 * @date: 2024/2/3 15:39
 * @version: 1.0
 * @description: 灰度图存储
 */
public class Main1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] compData = sc.nextLine().split(" ");
        String[] position = sc.nextLine().split(" ");// 带查找像素位置
        int r = Integer.parseInt(compData[0]);
        int c = Integer.parseInt(compData[1]);
        int targetRow = Integer.parseInt(position[0]);
        int targetCol = Integer.parseInt(position[1]);
        int[][] matrix = new int[r][c];
        int idx = 2;
        int vaule, count;
        int curRow = 0, curCol = 0;
        while (idx < compData.length) {
            vaule = Integer.parseInt(compData[idx++]);
            count = Integer.parseInt(compData[idx++]);
            for (int i = 0; i < count; i++) {
                matrix[curRow][curCol++] = vaule;
                if (curCol == c) {
                    curRow++;
                    curCol = 0;
                }
            }
        }
        int result = matrix[targetRow][targetCol];
        System.out.println(result);

    }
}
